package com.m2bshop.shop.controller;

import com.m2bshop.shop.pojo.Transaction;
import com.m2bshop.shop.service.TransactionService.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/trans")
@RestController
public class TransactionController {

    @Autowired
    TransactionService transactionService;

    @RequestMapping("/getAll/{userid}/{page}/{pageSize}")
    public List<Transaction> getUser(@PathVariable int userid, @PathVariable int page,@PathVariable int pageSize){
        if(page==0)
        {
            return  transactionService.getAllTransaction(userid,1,pageSize);
        }
        return transactionService.getAllTransaction(userid,page,pageSize);

    }
    @RequestMapping("/getOne/{userid}")
    public List<Transaction> getOne(@PathVariable int userid){
        return transactionService.getTransaction(userid);
    }
    @RequestMapping("/getAllTrans/{page}/{pageSize}")
    public List<Transaction> getAllTrans(@PathVariable int page,@PathVariable int pageSize){
        if(page==0)
        {
            return  transactionService.adminGetAll(1,pageSize);
        }
        return transactionService.adminGetAll(page,pageSize);

    }
}
